package com.sharemarking.application.common.api;


import java.util.HashMap;
import java.util.Map;

public class ResponseParams {

	private Integer errCode;
	private String errMsg;

	private Map<String, Object> data;

	private Map<String, Object> pageInfo;

	public Integer getErrCode() {
		return errCode;
	}

	public void setErrCode(Integer errCode) {
		this.errCode = errCode;
	}

	public String getErrMsg() {
		return errMsg;
	}

	public void setErrMsg(String errMsg) {
		this.errMsg = errMsg;
	}

	public Map<String, Object> getData() {
		return data;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

	public Map<String, Object> getPageInfo() {
		return pageInfo;
	}

	public void setPageInfo(Map<String, Object> pageInfo) {
		this.pageInfo = pageInfo;
	}

	public ResponseParams() {
		data = new HashMap<String, Object>();
	}

	public ResponseParams pageInfo(boolean hasNext, Integer pageIndex,
			Integer pageSize, Long total) {
		Map<String, Object> pageInfo = new HashMap<String, Object>();
		pageInfo.put("hasNext", hasNext);
		pageInfo.put("pageIndex", pageIndex);
		pageInfo.put("pageSize", pageSize);
		pageInfo.put("total", total);
		this.setPageInfo(pageInfo);
		return this;
	}

	public ResponseParams isSuccess() {
		this.setErrCode(HttpStatus.SUCCESS.getStatus());
		this.setErrMsg(HttpStatus.SUCCESS.getMessage());
		return this;
	}

	public ResponseParams isError() {
		this.setErrCode(HttpStatus.ERROR.getStatus());
		this.setErrMsg(HttpStatus.ERROR.getMessage());
		return this;
	}

	public ResponseParams isSignInvalid() {
		this.setErrCode(HttpStatus.SIGN_INVALID.getStatus());
		this.setErrMsg(HttpStatus.SIGN_INVALID.getMessage());
		return this;
	}

	public ResponseParams isRequiredParamsIsMissing(String msg) {
		this.setErrCode(HttpStatus.REQUIRED_PARAMS_IS_MISSING.getStatus());
		this.setErrMsg(HttpStatus.REQUIRED_PARAMS_IS_MISSING.getMessage() + "："
				+ msg);
		return this;
	}

	public ResponseParams isRequiredParamsError() {
		this.setErrCode(HttpStatus.REQUIRED_PARAMS_ERROR.getStatus());
		this.setErrMsg(HttpStatus.REQUIRED_PARAMS_ERROR.getMessage());
		return this;
	}

	public ResponseParams isDataError(String msg){
		this.setErrCode(HttpStatus.DATA_ERROR.getStatus());
		this.setErrMsg(HttpStatus.DATA_ERROR.getMessage() + ": "
				+ msg);
		return this;
	}
}
